<?php

namespace App\Http\Controllers\Api\V1;

use App\Services\Cache\MomentCache;
use App\Http\Controllers\Api\V1\Resources\MomentResource;
use App\Services\MakeMoment\MakeMomentRequest;
use App\Services\MakeMoment\CommonMomentRequest;
use App\Services\MakeMoment\CommentMomentRequest;
use App\Services\MakeMoment\ReplyMomentRequest;
use App\Services\MakeMoment\MakeMoment;
use App\Services\MakeMoment\likeMoment;
use App\Services\MakeMoment\CommentMoment;
use App\Services\MakeMoment\ReplyMoment;


class MomentsController extends Controller
{

	public function index()
	{
		$isAttention = request('isAttention');
		$moments = app(MomentCache::class)->moments($isAttention);
		return MomentResource::collection($moments);
	}

    public function store(MakeMomentRequest $request)
    {
    	$moment = app(MakeMoment::class, [
    		'user' => $request->user(),
		    'content' => $request->content,
		    'images' => $request->images,
	    ])->make();

	    return new MomentResource($moment);
    }


    public function like(CommonMomentRequest $request)
    {
    	app(likeMoment::class, [
    		'user' => $request->user(),
		    'moment' => $request->getMoment(),
	    ])->make();

	    return response(null, 204);
    }

    public function comment(CommentMomentRequest $request)
    {
    	app(CommentMoment::class, [
    		'user' => $request->user(),
		    'moment' => $request->getMoment(),
		    'content' => $request->content,
	    ])->create();

	    return response(null, 204);
    }

    public function reply(ReplyMomentRequest $request)
    {
    	

    	app(ReplyMoment::class, [
    		'user' => $request->user(),
		    'momentComment' => $request->getMomentComment(),
		    'replyId' => $request->parent_moment_reply_id,
		    'content' => $request->content,
	    ])->create();

	    return response(null, 204);
    }
}
